

from pages.base_page import BasePage
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select


class AddCustomerCare(BasePage):
    url = "/crm/index.php?m=customer&a=caresadd"
    result_locator = (By.XPATH, '/html/body/div[5]/div[2]')
    error_locator =(By.XPATH,"/html/body/div/form/fieldset/div[1]")
    customer_name_locator = (By.ID, 'customer_name')  # 客户
    contacts_name_locator = (By.ID, 'contacts_name')  # 联系人
    name_locator = (By.ID, 'name')  # 关怀主题
    care_time_locator = (By.ID, 'care_time')  # 关怀日期
    owner_name_locator = (By.ID, 'owner_name')  # 执行人
    typeOfCare_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tbody/tr[4]/td[4]/select')  # 关怀类型
    content_locator = (By.NAME, 'content')  # 关怀内容
    description_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tbody/tr[6]/td[2]/textarea')  # 备注
    save_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]')  # 保存

    def input_customer_name(self, customer_name):
        """
        输入客户名
        """
        self.find_element(self.customer_name_locator).send_keys(customer_name)

    def input_contacts_name(self, contacts_name):
        """
        输入联系人名
        """
        self.find_element(self.contacts_name_locator).send_keys(contacts_name)

    def input_care_name(self, care_name):
        """
        输入关怀主题
        """
        self.find_element(self.name_locator).send_keys(care_name)

    def input_care_time(self, care_time):
        """
        输入关怀日期
        """
        self.find_element(self.care_time_locator).send_keys(care_time)

    def input_owner_name(self, owner_name):
        """
        输入执行人
        """
        self.find_element(self.owner_name_locator).send_keys(owner_name)

    def select_typeOfCare(self, typeofcare_value):
        """
        选择关怀类型
        """
        typeofcare_element = Select(self.find_element(self.typeOfCare_locator))
        typeofcare_element.select_by_value(typeofcare_value)

    def input_content(self, content):
        """
        输入关怀内容
        """
        self.find_element(self.content_locator).send_keys(content)

    def input_description(self, description):
        """
        输入备注
        """
        self.find_element(self.description_locator).send_keys(description)

    def click_save(self):
        """
        点击保存
        """
        self.find_element(self.save_locator).click()

#返回增删改查后的提示信息
    def get_result_tips(self):
        return self.find_element(self.result_locator).text

#返回弹窗文本信息
    def get_alert_text(self):
        return self.driver.switch_to.alert.text

#返回报错弹窗文本信息
    def get_error_text(self):
        return self.find_element(self.error_locator).text

